#! /usr/bin/env node
const axios = require("axios");
const Table = require("cli-table2");
const inquirer = require("inquirer");
var prompt = inquirer.createPromptModule();

async function getCurData() {
    const { cityName } = await prompt({
        type: "input",
        name: "cityName",
        message: "请输入城市",
    })
    const { data } = await axios('https://restapi.amap.com/v3/weather/weatherInfo', {
        params: {
            key: 'acb101d6b96ab78d9bcf7b35abe8a95f',
            city: cityName
        }
    })
    var table = new Table({
        head: ["省份","城市","天气","时间"],
        style:{"text-align":0}
    });

    let {province,city,weather,reporttime} = data.lives[0];
    table.push(
        [province,city,weather,reporttime]
    );
    console.log(table+"");
}
getCurData();